<%-- 
    Document   : SearchItem
    Created on : 11 nov. 2012, 16:01:24
    Author     : Thomas
--%>

<%@page import="enterprise.web_jpa_war.entity.Type"%>
<%@page import="java.util.Map"%>
<%@page import="java.util.Vector"%>
<%@page import="enterprise.web_jpa_war.entity.Oeuvre"%>
<%@page import="enterprise.web_jpa_war.servlet.Fonctions"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <title>Mediatheque : Accueil</title>
        <meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
        <link type="text/css" rel="Stylesheet" media="screen" href="Css/design.css">
        <link type="text/css" rel="Stylesheet" media="screen" href="Css/bootstrap.min.css">
        <link href="Images/favicon.png" type="image/png" rel="icon">
    </head>
    <body>
        
        <%
        Fonctions f = new Fonctions();
        out.print(f.printNavBar());
        Vector<Oeuvre> oeuvres = (Vector<Oeuvre>) request.getAttribute("oeuvreList");
        Vector<Type> types = (Vector<Type>) request.getAttribute("typeList");
        Map<Oeuvre,Integer> nbDispos = (Map<Oeuvre,Integer>) request.getAttribute("nbDispoList");
        %>
        
        <div class="container-fluid">
            
        <%
        out.print(f.printSideBar());
        %>
            <div class="content">
                <div class="hero-unit">
                    <div class="page-header">
                        <h1 id="titre">Mediatheque : Catalogue des items</h1>
                        <h3>Recherchez des items dans le catalogue</h3>
                    </div>
                    <div class="well bloc_texte">
                        <form id="searchItem" action="FilteredCatalog" method="post">
                            <table>
                                <tr>
                                    <td>Nom</td>
                                    <td><input type="text" id="titreOeuvre" name="titreOeuvre" />
                                </tr>
                                <tr>
                                    <td>Auteur</td>
                                    <td><input type="text" id="auteurOeuvre" name="auteurOeuvre" />
                                </tr>
                                <tr>
                                    <td>Genre</td>
                                    <td><input type="text" id="genreOeuvre" name="genreOeuvre" />
                                </tr>
                                <tr>
                                    <td>Description</td>
                                    <td><input type="text" id="descOeuvre" name="descOeuvre" />
                                </tr>
                                <tr>
                                    <td>Type</td>
                                    <td><select id="type" name="type">
                                        <% if(types != null) { %>
                                        <option value=""></option>
                                            <% for(Type t : types) { %>
                                        <option value="<% out.print(t.getTypeName()); %>"><% out.print(t.getTypeName()); %></option>
                                        <% } } %>
                                    </td>
                                </select></td>
                                </tr>
                            </table>
                            <div class="actions" style="padding-left:0px">
                                <input id="btn_envoyer" class="btn large primary" type="submit" value="Rechercher">
                            </div>
                        </form>
                        <% 
                        if(oeuvres != null) {
                            if(!oeuvres.isEmpty()) {
                        %>
                        <table id="oeuvreListTable">
                            <tr>
                                <th>Titre</th>
                                <th>Auteur</th>
                                <th>Date d'edition</th>
                                <th>Genre</th>
                                <th>Description</th>
                                <th>Type</th>
                                <th>Nombre disponible</th>
                                <th>Action</th>
                            </tr>
                            <%
                            for(Oeuvre oeuvre : oeuvres){
                            %>
                            <tr>
                                <td><% out.print(oeuvre.getTitre()); %></td> 
                                <td><% out.print(oeuvre.getAuteur()); %></td> 
                                <td><% out.print(oeuvre.getDateEdition()); %></td>
                                <td><% out.print(oeuvre.getGenre()); %></td> 
                                <td><% out.print(oeuvre.getDescription()); %></td>
                                <td><% out.print(oeuvre.getType().getTypeName()); %></td>
                                <td><% out.print(nbDispos.get(oeuvre)); %></td>
                                <td>
                                <% if(nbDispos.get(oeuvre) > 0) { %>
                                <form <% out.print("action=\"AddToBasket?id=" + oeuvre.getId() + "\""); %> method="post">
                                <input id="<% oeuvre.getId(); %>" type="submit" value="Ajouter au panier" />
                                </form>
                                <%} else { %>
                                <form <% out.print("action=\"AddReservation?id=" + oeuvre.getId() + "\""); %> method="post">
                                <input id="<% oeuvre.getId(); %>" type="submit" value="Réserver" />
                                </form>
                                <%}%>
                                </td>
                            </tr>
                            <%
                            }
                            %>
                        </table>
                        <%
                            }
                            else {
                        %>
                        <h5>Aucun résultat trouvé.</h5>
                        <%
                            }
                        }
                        %>
                        <a href='index.jsp'><strong>retour au menu principal</strong></a>
                    </div>
                </div>
            </div>
        </div>
    </body>
</html>